package com.danciyixue.boot.client.userExtension.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.danciyixue.boot.common.result.PageResult;
import com.danciyixue.boot.common.result.Result;
import com.danciyixue.boot.dcyx.model.form.UserExtensionsForm;
import com.danciyixue.boot.dcyx.model.query.UserExtensionsQuery;
import com.danciyixue.boot.dcyx.model.vo.UserExtensionsVO;
import com.danciyixue.boot.dcyx.service.UserExtensionsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 客户端用户扩展信息控制器
 */
@Tag(name = "07. 用户扩展信息", description = "用户扩展信息")
@RestController
@RequestMapping("/api/client/v1/user-extension")
@RequiredArgsConstructor
public class DcyxUserExtensionController {

    private final UserExtensionsService userExtensionsService;

    /**
     * 获取用户扩展信息数据
     */
    @Operation(summary = "用户扩展配置信息分页列表")
    @GetMapping("/page")
    public PageResult<UserExtensionsVO> page(UserExtensionsQuery queryParams) {
        IPage<UserExtensionsVO> page = userExtensionsService.getUserExtensionsPage(queryParams);
        return PageResult.success(page);
    }

    /**
     * 根据 userToken 查询用户扩展信息
     */
    @Operation(summary = "用户扩展配置信息单个查询")
    @GetMapping("/me")
    public Result<UserExtensionsVO> me() {
        UserExtensionsVO result = userExtensionsService.getUserExtensionsByUserToken();
        return Result.success(result);
    }

    @Operation(summary = "新增OR修改用户扩展配置信息")
    @PostMapping
    public Result<Void> saveOrUpdateUserExtensions(@RequestBody @Valid UserExtensionsForm formData ) {
        boolean result = userExtensionsService.saveOrUpdateUserExtensions(formData);
        return Result.judge(result);
    }
} 